package cn.edu.kzjsxy.graduationproject.controller;


import cn.edu.kzjsxy.graduationproject.common.Page;
import cn.edu.kzjsxy.graduationproject.common.Result;
import cn.edu.kzjsxy.graduationproject.entity.StudentAbsences;
import cn.edu.kzjsxy.graduationproject.entity.StudentDormAssignments;
import cn.edu.kzjsxy.graduationproject.service.IStudentAbsencesService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学生缺勤记录表 前端控制器
 * </p>
 *
 * @author chén jiā jùn
 * @since 2024-04-14
 */
@Api(tags = "学生缺勤记录表")
@RestController
@RequestMapping("/student-absences")
public class StudentAbsencesController {

	@Autowired
	private IStudentAbsencesService studentAbsencesService;


	@GetMapping("/{absenceId}")
	@ApiOperation("根据学生缺勤记录ID查询学生缺勤记录信息")
	public Result<StudentAbsences> getStudentAbsencesById(@PathVariable String absenceId) {
		StudentAbsences studentAbsences = studentAbsencesService.getById(absenceId);
		return Result.success(studentAbsences);
	}

	@ApiOperation("添加学生缺勤记录")
	@PostMapping("/add")
	public Result addStudentAbsence(@RequestBody StudentAbsences studentAbsences) {
		boolean success = studentAbsencesService.save(studentAbsences);
		return Result.judgment(success);
	}

	@ApiOperation("删除学生缺勤记录")
	@DeleteMapping("/delete/{absenceId}")
	public Result deleteStudentAbsence(@PathVariable Integer absenceId) {
		boolean success = studentAbsencesService.removeById(absenceId);
		return Result.judgment(success);
	}

	@ApiOperation("更新学生缺勤记录")
	@PutMapping("/update")
	public Result updateStudentAbsence(@RequestBody StudentAbsences studentAbsences) {
		boolean success = studentAbsencesService.updateById(studentAbsences);
		return Result.judgment(success);
	}

	@ApiOperation("根据条件查询学生缺勤记录")
	@PostMapping("/list")
	public Result<List<StudentAbsences>> selectStudentAbsencesByCondition(@RequestBody StudentAbsences studentAbsences) {
		List<StudentAbsences> absencesList = studentAbsencesService.selectStudentAbsencesByCondition(studentAbsences);
		return Result.success(absencesList);
	}

	@ApiOperation("分页获取学生缺勤记录")
	@PostMapping("/page")
	public Result<PageInfo<StudentAbsences>> selectStudentAbsencesByPage(Page page , @RequestBody StudentAbsences studentAbsences) {
		return studentAbsencesService.selectStudentAbsencesByPage(page,studentAbsences);
	}

}
